// refund.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    disabled: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.showLoadings();

    this.setData({
      code: options.code
    })

    this.money(options.code);
  },

  // 退款金额
  money: function (code) {
    var that = this;
    wx.request({
      url: app.serviceurl + 'CarRental/CarRentalQueryRefundFee',
      header: {
        Authorization: "Bearer " + app.accesstoken
      },
      data: { OrderCode: code },
      dataType: 'json',
      success: function (res) {
        if (!res.data.Result) {
          wx.showModal({
            content: res.data.Message,
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.navigateBack({})
              }
            }
          });
        }
        that.setData({
          money: res.data
        });

        app.hideLoadings();
      },
      fail: function (res) {
        console.log(res)
        app.hideLoadings();
      }
    })
  },
  // Name提示框
  alert: function (message) {
    wx.showModal({
      content: message,
      showCancel: false,
      success: function (res) {
        if (res.confirm) {
          console.log('确定')
        }
      }
    });
  },
  // 退款
  backto: function (code) {
    this.setData({
      disabled: true
    })
    var that = this;
    wx.request({
      url: app.serviceurl + 'CarRental/CarRentalRefund',
      header: {
        Authorization: "Bearer " + app.accesstoken
      },
      data: { OrderCode: this.data.code },
      dataType: 'json',
      success: function (res) {
        if (res.data.Result == true) {
          wx.setStorage({
            key: 'refunds',
            data: res.data
          });
          wx.redirectTo({
            url: '/pages/paySuccess/paySuccess',
          })
        }else{
          that.alert(res.data.Message);
          return
        }
      },
      fail: function (res) {
        wx.navigateBack({});
        console.log(res);
      },
      complete: function () {
        var time = setTimeout(function () {
          that.setData({
            disabled: false
          });
        }, 1000)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
if (res.from === 'menu') {
      return app.OnShare();
    }
  },

})